package com.jx.controller.admin.statistics;

import com.jx.common.result.AjaxResult;
import com.jx.pojo.po.content.ItemPO;
import com.jx.service.statistics.StatisticsService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/statistics")
public class StatisticsController {

    @Resource
    private StatisticsService statisticsService;

    /**
     * 获取pv总数
     */
    @GetMapping("/getPVCount")
    public AjaxResult getPVCount() {
        Long count = statisticsService.getPVCount();
        return AjaxResult.success(count);
    }

    /**
     * 获取uv总数
     */
    @GetMapping("/getUVCount")
    public AjaxResult getUVCount() {
        Integer count = statisticsService.getUVCount();
        return AjaxResult.success(count);
    }

    /**
     * 统计pv和uv的变化趋势
     */
    @GetMapping("/countPvAndUv")
    public AjaxResult countPvAndUv() {
        Map<String, Object> result = statisticsService.countPvAndUv();
        return AjaxResult.success(result);
    }

    /**
     * 获取文章类别Top10
     */
    @GetMapping("/getArticleCategoryTopN")
    public AjaxResult getArticleCategoryTopN(Integer n) {
        List<ItemPO> result = statisticsService.getArticleCategoryTopN(n);
        return AjaxResult.success(result);
    }

    /**
     * 统计文章访问量
     */
    @GetMapping("/countArticleVisits")
    public AjaxResult countArticleVisits(Integer n) {
        Map<String, Object> result = statisticsService.countArticleVisits(n);
        return AjaxResult.success(result);
    }

}
